﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Dsl.Ped.AddIn.Java.Resources;
using Dsl.Ped.Framework.Common;
using Dsl.Ped.AddIn.Java.Generated.Interfaces;
using System.ComponentModel;
using Dsl.Ped.Framework.Projections;

namespace Dsl.Ped.AddIn.Java.Generated
{
    /// <summary>
    /// This is the class that enhances the <see cref="Field"/> class 
    /// provided in the model of projections, these are organized into containers
    /// </summary>
    public partial class Field : IProjective, IVariable, IDataErrorInfo
    {
        public override List<IProjectionContainer> GetProjectionContainers()
        {
            List<IProjectionContainer> containers = new List<IProjectionContainer>();
            containers.Add(
                new ProjectionContainer("Only Field")
                    .RegisterProjection("field", LayoutProjectionFactory.GetStackPanelProjection(
                        ValueProjectionFactory.GetTextBoxProjection(this, () => type, txt =>
                            {
                                txt.Foreground = Brushes.Blue; txt.VerticalContentAlignment = VerticalAlignment.Center; txt.VerticalAlignment = VerticalAlignment.Center;
                                txt.IsReadOnly = true;
                            }),
                        ValueProjectionFactory.GetTextBoxProjection(this, () => name, txt =>
                            {
                                txt.VerticalContentAlignment = VerticalAlignment.Center;
                                txt.VerticalAlignment = VerticalAlignment.Center;
                            }))) 
                    .RegisterProjection("cbx", LayoutProjectionFactory.GetStackPanelProjection(
                        ValueProjectionFactory.GetComboBoxProjection(this, () => type, JavaResources.DataTypes),
                        ValueProjectionFactory.GetTextBoxProjection(this, () => name, text =>
                            { text.VerticalContentAlignment = VerticalAlignment.Bottom; text.VerticalAlignment = VerticalAlignment.Bottom; })))
                    .RegisterTransition(TextBox.GotFocusEvent, "field", "cbx"));
                    
            containers.Add(
                new ProjectionContainer("Field")
                    .RegisterProjection("field", LayoutProjectionFactory.GetStackPanelProjection(
                        ValueProjectionFactory.GetTextBoxProjection(this, () => name, text =>
                            { text.VerticalContentAlignment = VerticalAlignment.Bottom; text.VerticalAlignment = VerticalAlignment.Bottom; }))));

            return containers;
        }

        #region IDataErrorInfo Members

        public string Error {
            get { throw new NotImplementedException(); 
            }
        }

        public string this[string propertyName] {
            get {
                string validationResult;
                switch (propertyName) {
                    case "name":
                        validationResult = validateName();
                        break;
                    default:
                        throw new ApplicationException("Unknown Property being validated on Deal.");
                }
                return validationResult;
            }
        }

        private string validateName() {
            return (String.IsNullOrEmpty(this.name)) ? "Variable must be specified" : String.Empty;
        }

        #endregion
    }
}
